package skill;

public class majorityElement {
    public int majorityElement(int[] nums) {
        int count=0;
        Integer candidate = null;
        for(int num:nums ){
            if (count==0) {
                candidate=num;
            }
            count+=(candidate==num)?1:-1;
        }
        return candidate;
    }

    public static void main(String[] args) {
        majorityElement obj = new majorityElement();
        int[] nums = new int[]{2,2,1,1,1,2,2};
        System.out.println(obj.majorityElement(nums));
    }
}
